package design.Singleton;

/**
 * Created by looper on 2017/8/14.
 */
public class Singleton {

  //保证外部不能通过构造方法实例化对象
  private Singleton(){

  }

  //使用内部类来维护单例
  public static class SingletonFactory{
    public static Singleton instance = new Singleton();
  }

  public Singleton getInsance(){
    return SingletonFactory.instance;
  }

  // 如果该对象被用于序列化，可以保证对象在序列化前后保持一致
  public Object readResolve() {
    return getInsance();
  }
}
